package com.quaidi.smartlocker.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.quaidi.smartlocker.entity.LockerCompartment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 智能柜格Mapper接口
 * 
 * @author QuaiDi
 * @since 2025-08-26
 */
@Mapper
public interface LockerCompartmentMapper extends BaseMapper<LockerCompartment> {

    /**
     * 根据尺寸和状态查找可用柜格
     */
    @Select("SELECT * FROM locker_compartment WHERE compartment_size = #{size} AND compartment_status = 'AVAILABLE' AND deleted = 0 LIMIT 1")
    LockerCompartment findAvailableCompartmentBySize(@Param("size") String size);

    /**
     * 获取按楼层分组的柜格列表
     */
    @Select("SELECT * FROM locker_compartment WHERE deleted = 0 ORDER BY floor_number, position_number")
    List<LockerCompartment> findAllGroupByFloor();
}